package cn.xiaopengstack.domain.agent.service.execute.flow;

import cn.bugstack.wrench.design.framework.tree.StrategyHandler;
import cn.xiaopengstack.domain.agent.model.entity.ExecuteCommandEntity;
import cn.xiaopengstack.domain.agent.service.execute.IExecuteStrategy;
import cn.xiaopengstack.domain.agent.service.execute.flow.factory.DefaultFlowAgentExecuteStrategyFactory;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter;

/**
 * @author jiangyangang
 */
@Service("flow")
@Slf4j
public class FlowAgentExecuteStrategy implements IExecuteStrategy {

    @Resource
    private DefaultFlowAgentExecuteStrategyFactory factory;

    @Override
    public void execute(ExecuteCommandEntity executeCommandEntity, ResponseBodyEmitter emitter) throws Exception {

        StrategyHandler<ExecuteCommandEntity, DefaultFlowAgentExecuteStrategyFactory.DynamicContext, String> handler = factory.getAgentStrategyHandler();

        handler.apply(executeCommandEntity, new DefaultFlowAgentExecuteStrategyFactory.DynamicContext());
    }
}
